﻿using System;
using System.Collections.Generic;

namespace BlockGame.Components
{
    public class Position
    {
        public Int32 Top { get; set; }
        public Int32 Left { get; set; }

        public Position()
        {
            Top = 0;
            Left = 0;
        }
        public Position(Int32 top, Int32 left)
        {
            Top = top;
            Left = left;
        }
    }

    public static class UiWriter
    {
        private static Position _OldPosition { get; set; }

        public enum Direction
        {
            Left,
            Center,
            Right
        }
        public static void WriteText(String text)
        {
            WriteText(text, Direction.Left);
        }
        public static void WriteText(String text, Position position)
        {
            WriteText(text, Direction.Left, position);
        }
        public static void WriteText(String text, Direction direction)
        {
            WriteText(text, direction, new Position(1, 1));
        }
        public static void WriteText(String text, Direction direction, Position position)
        {
            _OldPosition = new Position(Console.CursorTop, Console.CursorLeft);

            switch(direction)
            {
                case Direction.Left:
                    {
                        Console.CursorTop = position.Top;
                        Console.CursorLeft = position.Left;
                    } break;
                case Direction.Center:
                    {
                        Console.CursorTop = position.Top;
                        Console.CursorLeft = (((Int32)((Dictionary<String, Object>)Program.Settings.SettingsList["Window"])["Width"]) - text.Length) / 2;
                    } break;
                case Direction.Right:
                    {
                        Console.CursorTop = position.Top;
                        Console.CursorLeft = (((Int32)((Dictionary<String, Object>)Program.Settings.SettingsList["Window"])["Width"]) - text.Length);
                    } break;
            }

            Console.WriteLine(text);

            Console.CursorLeft = _OldPosition.Left;
            Console.CursorTop = _OldPosition.Top;
        }
    }
}